//
//  KDKVOMutableArray.m
//  DCTCustomer
//
//  Created by 姚宗超 on 14-9-15.
//  Copyright (c) 2014年 姚宗超. All rights reserved.
//

#import "KDKVOMutableArray.h"

@interface KDKVOMutableArray ()
@end

@implementation KDKVOMutableArray
@synthesize count;

+ (instancetype)array
{
    KDKVOMutableArray* array = [[KDKVOMutableArray alloc] init];
    return array;
}

- (instancetype)init
{
    if (self = [super init]) {
        _innerArray = [[NSMutableArray alloc] init];
    }
    return self;
}

- (NSMutableArray *)innerArray
{
    if (!_innerArray) {
        _innerArray = [NSMutableArray array];
    }
    return _innerArray;
}

- (NSUInteger)count
{
    return self.innerArray.count;
}

- (void)insertObject:(id)anObject atIndex:(NSUInteger)index
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray insertObject:anObject atIndex:index];
    [self didChangeValueForKey:@"count"];
}

- (void)removeObjectAtIndex:(NSUInteger)index
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray removeObjectAtIndex:index];
    [self didChangeValueForKey:@"count"];
}

- (void)addObject:(id)anObject
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray addObject:anObject];
    [self didChangeValueForKey:@"count"];
}

- (void)removeObject:(id)anObject
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray removeObject:anObject];
    [self didChangeValueForKey:@"count"];
}

- (void)removeLastObject
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray removeLastObject];
    [self didChangeValueForKey:@"count"];
}

- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray insertObjects:objects atIndexes:indexes];
    [self didChangeValueForKey:@"count"];
}

- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray replaceObjectAtIndex:index withObject:anObject];
    [self didChangeValueForKey:@"count"];
}

- (BOOL)containsObject:(id)anObject
{
    return [self.innerArray containsObject:anObject];
}

- (id)objectAtIndex:(NSUInteger)objectIndex
{
    if (self.innerArray.count <= 0) {
        return nil;
    }
    return [self.innerArray objectAtIndex:objectIndex];
}

- (void)removeAllObjects
{
    [self willChangeValueForKey:@"count"];
    [self.innerArray removeAllObjects];
    [self didChangeValueForKey:@"count"];
}

@end
